#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:course_controller.py
# author:张世航
# datetime:2024/12/21 01:30
# software: PyCharm
"""
this is function  description 
"""
# controller/course_controller.py
from models.course import Course
from utils.db import Session

def add_course(cno, cname, chours, credit, tno, student_count):
    session = Session()
    new_course = Course(Cno=cno, Cname=cname, Chours=chours, Credit=credit, Tno=tno, StudentCount=student_count)
    session.add(new_course)
    session.commit()
    session.close()

def delete_course(cno):
    session = Session()
    course = session.query(Course).filter(Course.Cno == cno).first()
    if course:
        session.delete(course)
        session.commit()
    session.close()

def query_course_by_name(name):
    session = Session()
    courses = session.query(Course).filter(Course.Cname == name).all()
    session.close()
    return courses